package com.studentSystem.controller;

import com.studentSystem.dto.StatisticModel;
import com.studentSystem.service.StatisticService;
import com.studentSystem.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/statistic")
public class StastiticController {
    private final String[] LABELS = new String[]{"0-59", "60-69", "70-79", "80-89", "90-100"};
    private final String[] STANDARD = new String[]{
            "BETWEEN 0 AND 59",
            "BETWEEN 60 AND 69",
            "BETWEEN 70 AND 79",
            "BETWEEN 80 AND 89",
            "BETWEEN 90 AND 100"
    };
    private final String[] GENDER = new String[]{"男", "女"};

    @Autowired
    private StatisticService statisticService;

    @GetMapping("/courseGrade")
    public ResultUtil<List<StatisticModel>> courseGrade(Long courseId){
        List<StatisticModel> list = new ArrayList<>();
        for(int i=0; i<5; i++){
            StatisticModel statisticModel = new StatisticModel();
            statisticModel.setName(LABELS[i]);
            Integer count = statisticService.findcourseGrade(STANDARD[i], courseId);
            statisticModel.setValue(count);
            list.add(statisticModel);
        }
        return ResultUtil.success(list);
    }

    @GetMapping("/studentAddress")
    public ResultUtil<List<StatisticModel>> studentAddress(Long classId){
        List<String> studentAddressCount = statisticService.studentAddressCount(classId);
        List<StatisticModel> list = new ArrayList<>();
        for (int i=0; i<studentAddressCount.size(); i++){
            StatisticModel statisticModel = new StatisticModel();
            statisticModel.setName(studentAddressCount.get(i));
            Integer count = statisticService.findStudentAddress(studentAddressCount.get(i),classId);
            statisticModel.setValue(count);
            list.add(statisticModel);
        }
        return ResultUtil.success(list);
    }

    @GetMapping("/cLassStudentNum")
    public ResultUtil<List<StatisticModel>> cLassStudentNum(Long classId){
        List<StatisticModel> list = new ArrayList<>();
        for (int i=0; i<2; i++){
            StatisticModel statisticModel = new StatisticModel();
            statisticModel.setName(GENDER[i]);
            Integer count = statisticService.cLassStudentNum(classId, GENDER[i]);
            statisticModel.setValue(count);
            list.add(statisticModel);
        }
        return ResultUtil.success(list);
    }
}
